import { useSelector } from "react-redux";
import { Redirect } from "react-router-dom";
function Guards({ Cmp, ...props }) {
    const { user } = useSelector(state => state)
    if (user) {
        return <Cmp {...props} />
    }
    return <Redirect to="/login" />
}

function withGuards(Cmp) {
    return (props) => {
        return <Guards Cmp={Cmp} {...props} />
    }
}

// 导出封装验证的高阶组件
// 解决的问题就是复用某种逻辑
export default withGuards